package flc.ast.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.adapter.ContentAdapter;
import flc.ast.databinding.DialogQuestionStyleBinding;
import stark.common.basic.base.BaseSmartDialog;

public class QuestionDialog extends BaseSmartDialog<DialogQuestionStyleBinding> {
    private List<String> content = new ArrayList<>();
    private ContentAdapter mContentAdapter;


    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    public QuestionDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_question_style;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.rvList.setLayoutManager(new LinearLayoutManager(getContext()));
        mContentAdapter = new ContentAdapter();
        mDataBinding.rvList.setAdapter(mContentAdapter);
        getQuestionData();
        mContentAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                listener.clickQuestion(position);
                dismiss();
            }
        });
    }


    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickQuestion(int position);
    }

    private void getQuestionData() {
        content.add(getContext().getString(R.string.answer_problem1));
        content.add(getContext().getString(R.string.answer_problem2));
        content.add(getContext().getString(R.string.answer_problem3));
        content.add(getContext().getString(R.string.answer_problem4));
        mContentAdapter.selContent = content.get(0);
        mContentAdapter.setList(content);
    }
}
